<?php
if(!empty($_POST) AND !isset($_POST['Entry']))
{
	if($_POST['scharfschuetzen'] != 0) { UpdateGround('scharfschuetzen', $_POST['scharfschuetzen']); }
	if($_POST['maschingewehr'] != 0) { UpdateGround('maschingewehr', $_POST['maschingewehr']); }
	if($_POST['lasergewehr'] != 0) { UpdateGround('lasergewehr', $_POST['lasergewehr']); }
	if($_POST['bazooka'] != 0) { UpdateGround('bazooka', $_POST['bazooka']); }
	if($_POST['sprengsatz'] != 0) { UpdateGround('sprengsatz', $_POST['sprengsatz']); }
}
$result = RequestData('waffen');
$building = RequestData('buildings');
$science = RequestData('forschung');
$ressource = RequestData('resource');
?>
<form method="post" action="">
	<table class="buildings" style="table-layout: fixed; width: 720px;">
		<colgroup>
			<col style="width:115px;">
			<col style="width:auto;">
			<col style="width:100px">
		</colgroup>
		<thead>
			<td>Waffenfabrik</td>
		</thead>
		<?php
			$con = Connect();
			$check = mysql_query("SELECT * FROM waffen_build ORDER BY Waffenfabrik_LVL");
			while($object = mysql_fetch_object($check))
			{
				$lock = array(false, false, false, false, false);
				if($building['Waffen'] >= $object->Waffenfabrik_LVL) //Check if it should be shown or not
				{
					echo '<tr><th><img src="../Game/template/Images/waffen/'.$object->Name.'.png"></th>';
					echo '<th><p>'.$object->Name.'['.$result[$object->Name].']</p><p>'.$object->Description.'</p>';
					echo '<p>Zeit: '.$object->Time.'</p><p>Ben&ouml;tigt: ';
					if($science['Laser'] < $object->Laser)
					{
						echo '<b style="color:#FF0000;"> Laser-Technik Stufe '.$object->Laser.'</b>,'; 
						$lock[0] = true;
					}else{
						echo '<b style="color:#00FF00;"> Laser-Technik Stufe '.$object->Laser.'</b>,'; 
					}
					if($science['Munition'] < $object->Munition)
					{
						echo '<b style="color:#FF0000;"> Munitions Entwicklung Stufe '.$object->Munition.'</b></p>'; 
						$lock[1] = true;
					}else{
						echo '<b style="color:#00FF00;"> Munitions Entwicklung Stufe '.$object->Munition.'</b></p>';
					}
					echo '<p>Ressourcen: ';
					if($ressource['Credits'] < $object->Credits)
					{
						echo '<b style="color:#FF0000;">'.$object->Credits.' Credits</b>, ';
						$lock[2] = true;
					}else{
						echo '<b style="color:#00FF00;">'.$object->Credits.' Credits</b>, ';
					}
					if($ressource['Titan'] < $object->Titan)
					{
						echo '<b style="color:#FF0000;">'.$object->Titan.' Titan</b>, ';
						$lock[3] = true;
					}else{
						echo '<b style="color:#00FF00;">'.$object->Titan.' Titan</b>, ';
					}
					if($ressource['Oel'] < $object->Oel)
					{
						echo '<b style="color:#FF0000;">'.$object->Oel.' &Ouml;l</b>';
						$lock[4] = true;
					}else{
						echo '<b style="color:#00FF00;">'.$object->Oel.' &Ouml;l</b>';
					}
					if($object->Benzin != 0)
					{
						if($ressource['Benzin'] < $object->Benzin)
						{
							echo ', <b style="color:#FF0000;">'.$object->Benzin.' Benzin</b></p></th>';
							$lock[5] = true;
						}else{
							echo ', <b style="color:#00FF00;">'.$object->Benzin.' Benzin</b></p></th>';
						}
					}else{ echo '</p></th>'; }
					echo '<th><p>Einheiten: </p><p><input type="number" name="'.$object->Name.'" value="0" min="0" max="50" style="width:80px;" ';
					if($lock[0] == true || $lock[1] == true || $lock[2] == true || $lock[3] == true || $lock[4] == true || $lock[5] == true) echo 'disabled';
					echo '></p><br><p><input type="submit" name="ground"></p></th></tr>';
				}
			}
			Close($con);
		?>
	</table>
</form>